package com.naodong.shenluntiku.mvp.view.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.naodong.shenluntiku.R;
import com.naodong.shenluntiku.mvp.model.bean.SubjectType;
import com.naodong.shenluntiku.mvp.model.bean.SupportFragmentWrap;
import com.naodong.shenluntiku.mvp.view.adapter.LittleFragmentAdapter;
import com.naodong.shenluntiku.mvp.view.fragment.SubjectAnalysisListFragment;
import com.yatatsu.autobundle.AutoBundleField;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import me.shingohu.man.base.BaseMVPActivity;
import me.shingohu.man.di.component.AppComponent;

/**
 * Created by hujie on 17/4/20.
 *
 * 单题解析列表
 */

public class SubjectAnalysisListActivity extends BaseMVPActivity {

    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @AutoBundleField
    ArrayList<SubjectType> subjectTypeList;
    LittleFragmentAdapter pagerAdapter;



    @Override
    protected void onCreateInit(Bundle savedInstanceState) {

        initViewPager();
        setTabLayout();
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    private void initViewPager() {

        pagerAdapter = new LittleFragmentAdapter(getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    private void setTabLayout() {
        List<SupportFragmentWrap> fragmentWrapList = new ArrayList<>();
        for (SubjectType subjectType : subjectTypeList) {
            TabLayout.Tab tabItem = tabLayout.newTab();
            tabItem.setTag(subjectType.getSubTypeId());
            tabItem.setText(subjectType.getName());
            tabLayout.addTab(tabItem);
            fragmentWrapList.add(new SupportFragmentWrap(subjectType.getName(), SubjectAnalysisListFragment.getInstance(subjectType)));
        }
        pagerAdapter.setFragments(fragmentWrapList);
        pagerAdapter.notifyDataSetChanged();

    }

    @Override
    protected int layoutId() {
        return R.layout.a_subjectanalysis_list;
    }

    @Override
    protected boolean userAutoBindBundle() {
        return true;
    }

}
